package com.px.controller;

import com.px.mapper.ShUserMapper;
import com.px.pojo.ShUser;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class ProviderShUserController {

    @Resource
    private ShUserMapper shUserMapper;

    @PostMapping("/api/provider/selectShUserList")
    public List<ShUser> selectShUserList(@RequestParam String userName, @RequestParam Integer id,
                                         @RequestParam Integer pageBegin, @RequestParam Integer pageSize)throws Exception{
        List<ShUser> shUsers = shUserMapper.selectUserList(userName, id, pageBegin, pageSize);
        if("".equals(shUsers) && null == shUsers){
            return null;
        }
        return shUsers;
    }

    @PostMapping("/api/provider/selectShUserCount")
    public Integer selectShUserCount(@RequestParam String userName, @RequestParam Integer id)throws Exception{
        int count = shUserMapper.selectUserCount(userName, id);
        if (count > 0) {
            return count;
        }
        return 0;
    }

    @PostMapping("/api/provider/selectShUser")
    public ShUser selectShUser(@RequestParam Integer userId)throws Exception{
        ShUser shUser = shUserMapper.selectUser(userId);
        if("".equals(shUser) && null == shUser){
            return null;
        }
        return shUser;
    }

    @PostMapping("/api/provider/insertShUser")
    public Integer insertShUser(@RequestBody ShUser shUser)throws Exception{
        int insert = shUserMapper.insertUser(shUser);
        if (insert > 0) {
            return insert;
        }
        return 0;
    }

    @PostMapping("/api/provider/updateShUser")
    public Integer updateShUser(@RequestBody ShUser shUser)throws Exception{
        int update = shUserMapper.updateUser(shUser);
        if (update > 0) {
            return update;
        }
        return 0;
    }

    @PostMapping("/api/provider/deleteShUser")
    public Integer deleteShUser(@RequestParam Integer id)throws Exception{
        int delete = shUserMapper.deleteUser(id);
        if (delete > 0) {
            return delete;
        }
        return 0;
    }
}
